/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file    light_sensor.h
  * @brief   This file contains all the function prototypes for
  *          the light_sensor.c file
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LIGHT_SENSOR_H__
#define __LIGHT_SENSOR_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "adc.h"
#include <stdint.h>  // 添加这行来定义uint8_t和uint16_t类型

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private defines -----------------------------------------------------------*/
/* USER CODE BEGIN Private defines */

// 光敏传感器配置参数
#define LIGHT_SENSOR_ADC_HANDLE     &hadc1          // ADC句柄
#define LIGHT_SENSOR_ADC_TIMEOUT    100             // ADC转换超时时间(ms)
#define LIGHT_SENSOR_DEFAULT_THRESHOLD  300        // 默认光照阈值

// LED控制配置
#define LIGHT_SENSOR_LED_PORT       LED1_GPIO_Port           // LED端口
#define LIGHT_SENSOR_LED_PIN        LED1_Pin        // LED引脚

/* USER CODE END Private defines */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

// 光敏传感器状态枚举
typedef enum {
    LIGHT_SENSOR_OK = 0,
    LIGHT_SENSOR_ERROR,
    LIGHT_SENSOR_TIMEOUT
} LightSensor_StatusTypeDef;

// 光照状态枚举
typedef enum {
    LIGHT_STATE_BRIGHT = 0,     // 明亮
    LIGHT_STATE_DARK            // 黑暗
} LightSensor_StateTypeDef;

// 光敏传感器配置结构体
typedef struct {
    uint16_t threshold;         // 光照阈值
    uint8_t auto_led_control;   // 自动LED控制使能
    uint8_t invert_logic;       // 反转逻辑（1：亮时点亮LED，0：暗时点亮LED）
} LightSensor_ConfigTypeDef;

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
/* USER CODE BEGIN EFP */

// 初始化函数
LightSensor_StatusTypeDef LightSensor_Init(LightSensor_ConfigTypeDef *config);

// 读取光敏传感器原始值
LightSensor_StatusTypeDef LightSensor_ReadRaw(uint16_t *value);

// 获取光照状态
LightSensor_StateTypeDef LightSensor_GetState(void);

// 设置阈值
void LightSensor_SetThreshold(uint16_t threshold);

// 获取阈值
uint16_t LightSensor_GetThreshold(void);

// LED控制函数
void LightSensor_LED_Control(LightSensor_StateTypeDef state);

// 自动LED控制（根据光照状态自动控制LED）
void LightSensor_AutoLEDControl(void);

// 使能/禁用自动LED控制
void LightSensor_SetAutoLEDControl(uint8_t enable);

// 设置逻辑反转
void LightSensor_SetInvertLogic(uint8_t invert);

/* USER CODE END EFP */

#ifdef __cplusplus
}
#endif

#endif /* __LIGHT_SENSOR_H__ */